#include "aed_rendercomp.h"

AED_RenderComp::AED_RenderComp()
{
    m_image = 0;
    m_visible=true;
    m_text=false;
    m_layer = 5;
    m_alpha = 1.0;
    m_enabled = false;
}

AED_RenderComp& AED_RenderComp::operator =(const AED_RenderComp &comp){
    m_image = comp.m_image;
    m_visible = comp.m_visible;
    m_text = comp.m_text;
    m_layer = comp.m_layer;
    m_alpha = comp.m_alpha;
    m_enabled = comp.m_enabled;

    return *this;
}

AED_Image* AED_RenderComp::GetImage(){
    return m_image;
}

void AED_RenderComp::SetImage(AED_Image *img){
    m_image = img;
}

bool AED_RenderComp::GetVisible(){
    return m_visible;
}

void AED_RenderComp::SetVisible(bool vis){
    m_visible = vis;
}

bool AED_RenderComp::GetText(){
    return m_text;
}

void AED_RenderComp::SetText(bool text){
    m_text = text;
}

int AED_RenderComp::GetLayer(){
    return m_layer;
}

void AED_RenderComp::SetLayer(int layer){
    m_layer = layer;
}

float AED_RenderComp::GetAlpha(){
    return m_alpha;
}

void AED_RenderComp::SetAlpha(float alpha){
    m_alpha = alpha;
}

bool AED_RenderComp::IsEnabled(){
    return m_enabled;
}

void AED_RenderComp::SetEnabled(bool enabled){
    m_enabled = enabled;
}

void AED_RenderComp::Save(QTextStream &file){
    if(!m_enabled)
        return;

    file << "   <component = Render>" << endl;
    file << "      <image = " << m_image->GetName() << ">" << endl;
    file << "      <visible = " << m_visible << ">" << endl;
    file << "      <text = " << m_text << ">" << endl;
    file << "      <layer = " << m_layer << ">" << endl;
    file << "      <alpha = " << m_alpha << ">" << endl;
    file << "   </component>" << endl;
}

void AED_RenderComp::Save(QDomDocument &doc, QDomElement &pelem){
    if(!m_enabled)
        return;

    if(!m_image)
        return;
    QDomElement elem = doc.createElement("component");
    elem.setAttribute("comptype","Render");
    elem.setAttribute("image",m_image->GetPath());
    elem.setAttribute("visible",m_visible);
    elem.setAttribute("text",m_text);
    elem.setAttribute("layer",m_layer);
    elem.setAttribute("alpha",m_alpha);

    pelem.appendChild(elem);
}

void AED_RenderComp::Load(QDomElement &celem, ImageManager &imgmngr){
    m_enabled = true;

    m_image = imgmngr.GetImage(celem.attribute("image"));
    m_visible = celem.attribute("visible").toInt();
    m_text = celem.attribute("text").toInt();
    m_layer = celem.attribute("layer").toInt();
    m_alpha = celem.attribute("alpha").toFloat();

}
